package one.two.two;

import java.util.Scanner;

import edu.princeton.cs.algs4.Interval1D;

public class Intersection {

	private static boolean between(double a, double b, double c) {
		if (a >= b && a <= c)
			return true;
		return false;
	}

	private static boolean inte(Interval1D a, Interval1D b) {
		boolean r = false;
		if (a == null || b == null) {
			return r;
		}
		if (between(a.min(), b.min(), b.max()) || between(a.max(), b.min(), b.max())
				|| between(b.min(), a.min(), a.max()) || between(b.max(), a.min(), a.max()))
			r = true;
		return r;
	}

	public static void mains(String[] args) {
		Interval1D a = new Interval1D(0.5, 0.6);
		Interval1D b = new Interval1D(0.5, 0.6);

		System.out.println(inte(a, b));
	}

	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		System.out.println("n intervals:");
		Interval1D[] a = new Interval1D[n];
		double min, max;
		for (int i = 0; i < n; i++) {
			min = s.nextDouble();
			max = s.nextDouble();
			a[i] = new Interval1D(min, max);
		}
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (inte(a[i], a[j])) {
					System.out.println(a[i] + " intersect " + a[j]);
				}
			}
		}

	}

}
